package com.bdf.ipharma.gui;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.JOptionPane;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;

import org.apache.log4j.Logger;

import com.bdf.ipharma.config.Session;
import com.bdf.ipharma.model.Usuario;
import com.bdf.ipharma.starter.McdMain;
import com.bdf.ipharma.starter.McdPrs;

/**
 * @author toti
 *
 */
public class GUIHeaderComponent extends GUIWindow{

	private Session session;
	private Usuario usuario;
	private McdMain mcdMain;
	static final Logger logger = Logger.getLogger(GUIHeaderComponent.class);
	
	public GUIHeaderComponent(McdMain pMain) {
		super(pMain);
		session = pMain.getSession();
		usuario = session.getUsuario();
		mcdMain = pMain;
		init();
	}



	/**
	 * 
	 */
	
	
	private JLabel leyenda1 = null;
	
	private static final long serialVersionUID = 1L;
	
	
	public void init(){
		this.setSize(800,130);
		this.setOpaque(true);
		
		GUIButtonImage jBtnExit = new GUIButtonImage("",Images.buttHome,Images.buttHomeDn);
		
		
		GUIButtonImage jBtnHelp = new GUIButtonImage("",Images.buttHelp,Images.buttHelpDn);
		
		
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap(683, Short.MAX_VALUE)
					.addComponent(jBtnHelp, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(jBtnExit, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
					.addGap(38))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(21)
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(jBtnExit, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 42, Short.MAX_VALUE)
						.addComponent(jBtnHelp, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 42, Short.MAX_VALUE))
					.addGap(67))
		);
		setLayout(groupLayout);
		
		
		jBtnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent((Component) e.getSource()),
						McdPrs.MENSAJE_AYUDA_REPOSICION_PRODUCTO);
				
			}
		});
		
		//Eventos
		//Logout
		jBtnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				logger.debug("Presionado boton de HOME");
				session.disposeSession();
				//session.removeUser();
				mcdMain.start();
			}
		});
	}
	
	
	
	public void paintComponent(Graphics g) {
		g.drawImage(Images.bgHeader.getImage(), 0, 0, null);
	}



    public void setLeyenda1(String leyenda){
    	this.leyenda1.setText(leyenda);
    }
	
}
